package com.sgq.vue.controller.resource;

import com.sgq.vue.entity.resource.City;
import com.sgq.vue.result.Result;
import com.sgq.vue.service.resource.CityService;
import com.sgq.vue.vo.query.resource.CityQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author: 83778
 * @date: 2023-12-19 17:14
 * @desc:
 */

@RestController
@RequestMapping("/api/resource/city")
public class CityController {

    @Autowired
    private CityService cityService;


    //条件查询省下的市
    @PreAuthorize("hasAuthority('resource:city:list')")
    @GetMapping("/getCityByProvinceName")
    public Result getCityByProvinceName(CityQueryVo dictVo){
        List<City> cities = cityService.findCityByProvinceName(dictVo);
        return  Result.ok(cities);
    }

    //查询明确省下的市
    @PreAuthorize("hasAuthority('resource:city:list')")
    @GetMapping("/getCity/{leaderCode}")
    public Result getCity(@PathVariable("leaderCode") Long leaderCode){
        List<City> cities = cityService.findCityByLeaderCode(leaderCode);
        return  Result.ok(cities);
    }


    @GetMapping("/exportCity")
    public void exportCity(HttpServletResponse response){
        cityService.exportCity(response);
    }


    @PostMapping("/importCity")
    public Result importCity(MultipartFile file){
        cityService.importCity(file);
        return  Result.ok();
    }



}
